import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';

// 切换俱乐部选择头像
class ClubAvatarDialog {

  static void show(
    BuildContext mContext, {
      Function? proposeTap,
      Function? phoneTap,
      Function? shootTap,
      String title = '俱乐部头像',
      bool isRecommend = true
    }
  ) {
    showDialog(
      // barrierDismissible: false,
      context: mContext,
      builder: (BuildContext context) {
        return ShowDialogPage(
          phoneTap: phoneTap,
          proposeTap: proposeTap,
          shootTap: shootTap,
          title: title,
          isRecommend: isRecommend
        );
      }
    );
  }

}




class ShowDialogPage extends Dialog {
  ShowDialogPage({
    this.proposeTap,
    this.phoneTap,
    this.shootTap,
    this.title = '俱乐部头像',
    this.isRecommend = true
  });

  // 推荐
  final Function? proposeTap;
  // 相册
  final Function? phoneTap;
  // 拍照
  final Function? shootTap;

  final String title;

  final bool isRecommend;

  @override
  Widget build(BuildContext dContext) {
    return Material(
      //创建透明层
      type: MaterialType.transparency, //透明类型
      //自定义dialog布局
      child: Center(
        child: RichText(
          text: TextSpan(
            children: [
              WidgetSpan(
                child: Container(
                  margin: EdgeInsets.symmetric(horizontal: 40.w),
                  width: double.infinity,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(12.r)
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        alignment: Alignment.center,
                        height: 48.w,
                        decoration: BoxDecoration(
                          gradient: const LinearGradient(
                            begin: Alignment.topCenter,
                            end: Alignment.bottomCenter,
                            colors: [
                              Color(0xFFEAF9EF),
                              Color(0x00EAF9EF),
                            ],
                            stops: [0.0, 1.0],
                          ),
                          borderRadius: BorderRadius.circular(12.r)
                        ),
                        child: Text(title, style: TextStyle(fontSize: 17.sp, fontWeight: FontWeight.w500, color: const Color(0xff333333), ), textAlign: TextAlign.center,),
                      ),

                      SizedBox(height: 12.w,),

                      if (isRecommend == true) ...[
                        GestureDetector(
                          behavior: HitTestBehavior.translucent,
                          onTap: () {
                            proposeTap?.call();
                          },
                          child: Container(
                            padding: EdgeInsets.symmetric(vertical: 10.w),
                            alignment: Alignment.center,
                            child: Text('选择推荐头像', style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w400, color: const Color(0xff333333), ), textAlign: TextAlign.center,),
                          ),
                        ),

                        SizedBox(height: 12.w,),
                      ],

                      GestureDetector(
                        behavior: HitTestBehavior.translucent,
                        onTap: () {
                          phoneTap?.call();
                        },
                        child: Container(
                          padding: EdgeInsets.symmetric(vertical: 10.w),
                          alignment: Alignment.center,
                          child: Text('从相册中选择照片', style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w400, color: const Color(0xff333333), ), textAlign: TextAlign.center,),
                        ),
                      ),

                      SizedBox(height: 12.w,),

                      GestureDetector(
                        behavior: HitTestBehavior.translucent,
                        onTap: () {
                          shootTap?.call();
                        },
                        child: Container(
                          padding: EdgeInsets.symmetric(vertical: 10.w),
                          alignment: Alignment.center,
                          child: Text('拍照', style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w400, color: const Color(0xff333333), ), textAlign: TextAlign.center,),
                        ),
                      ),


                      SizedBox(height: 16.w,),
                    ],
                  ),
                )
              ),
            ]
          ),
        ),
      )
    );
  }
}



